package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesProcessItems;
import com.ruoyi.mes.service.IMesProcessItemsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺规程-物料Controller
 *
 * @author ruoyi
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/processItems")
public class MesProcessItemsController extends BaseController
{
    @Autowired
    private IMesProcessItemsService mesProcessItemsService;

    /**
     * 查询工艺规程-物料列表
     */
    @PreAuthorize(hasPermi = "mes:processItems:list")
    @GetMapping("/list")
    public TableDataInfo list(MesProcessItems mesProcessItems)
    {
        startPage();
        List<MesProcessItems> list = mesProcessItemsService.selectMesProcessItemsList(mesProcessItems);
        return getDataTable(list);
    }

    /**
     * 导出工艺规程-物料列表
     */
    @PreAuthorize(hasPermi = "mes:processItems:export")
    @Log(title = "工艺规程-物料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProcessItems mesProcessItems) throws IOException
    {
        List<MesProcessItems> list = mesProcessItemsService.selectMesProcessItemsList(mesProcessItems);
        ExcelUtil<MesProcessItems> util = new ExcelUtil<MesProcessItems>(MesProcessItems.class);
        util.exportExcel(response, list, "工艺规程-物料数据");
    }

    /**
     * 获取工艺规程-物料详细信息
     */
    @PreAuthorize(hasPermi = "mes:processItems:query")
    @GetMapping(value = "/{processItemUuid}")
    public AjaxResult getInfo(@PathVariable("processItemUuid") String processItemUuid)
    {
        return AjaxResult.success(mesProcessItemsService.selectMesProcessItemsByProcessItemUuid(processItemUuid));
    }

    /**
     * 新增工艺规程-物料
     */
    @PreAuthorize(hasPermi = "mes:processItems:add")
    @Log(title = "工艺规程-物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProcessItems mesProcessItems)
    {
        return toAjax(mesProcessItemsService.insertMesProcessItems(mesProcessItems));
    }

    /**
     * 修改工艺规程-物料
     */
    @PreAuthorize(hasPermi = "mes:processItems:edit")
    @Log(title = "工艺规程-物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProcessItems mesProcessItems)
    {
        return toAjax(mesProcessItemsService.updateMesProcessItems(mesProcessItems));
    }

    /**
     * 删除工艺规程-物料
     */
    @PreAuthorize(hasPermi = "mes:processItems:remove")
    @Log(title = "工艺规程-物料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{processItemUuids}")
    public AjaxResult remove(@PathVariable String[] processItemUuids)
    {
        return toAjax(mesProcessItemsService.deleteMesProcessItemsByProcessItemUuids(processItemUuids));
    }
}